<?php

namespace App\Http\Controllers;


use App\Http\Model\Hint;
use App\Http\Model\OutJson;
use App\Http\Services\ConfigServices;
use App\Http\Services\TaskServices;
use Illuminate\Http\Request;


//点亮卡活动
class TaskController extends Controller
{
    private $configServices;
    private $TaskServices;


    public function __construct()
    {
        $this->configServices = new ConfigServices();
        $this->TaskServices = new TaskServices();
    }

    //获取基础信息
    public function getTaskInfo(Request $request)
    {
        $user_id = $request->input('user_id');
        if (intval($user_id) == 0) OutJson::toJson(-1, '失败');
        $res = $this->TaskServices->getTaskInfo($user_id);
        OutJson::toJson($res['code'], $res['msg'], $res['data']);
    }

    //刷新任务
    public function refreshTask(Request $request)
    {
        $this->checkActivityDate(30, 'task_date', '瓜分阶段,任务已关闭~');
        $user_id = $request->input('user_id', '0');
        if (!$user_id) OutJson::toJson(-1, '失败');
        $res = $this->TaskServices->refreshTask($user_id);
        OutJson::toJson($res['code'], $res['msg'], []);
    }


    //任务完成情况
    public function completeTask(Request $request)
    {
        $this->checkActivityDate(30, 'task_date');
        $user_id = $request->input('user_id', '0');
        if (intval($user_id) == 0) OutJson::toJson(-1, '失败');
        $this->TaskServices->completeFreeTask($user_id);
        $this->TaskServices->completeSuperTask($user_id);
        OutJson::toJson(0);
    }

    //定时任务 完成情况
    public function allUserCompleteTask(Request $request)
    {
        $this->checkActivityDate(30, 'task_date');
        $this->TaskServices->getSuperUserList();
        OutJson::toJson(0);
    }

    //领取奖励
    public function clickAwardDiamond(Request $request)
    {
        $this->checkActivityDate(31, 'task_award_date', '亲~3月31日0点整瓜分，请耐心等待~');
        $user_id = $request->input('user_id', '0');
        if (!$user_id) OutJson::toJson(-1, '失败');
        $res = $this->TaskServices->clickAwardDiamond($user_id);
        OutJson::toJson($res['code'], $res['msg'], $res['data']);
    }

    public function getInvite(Request $request)
    {
        $user_id = $request->input('user_id', '0');
        if (!$user_id) OutJson::toJson(-1, '失败');
        $res = $this->TaskServices->getInvite($user_id);
        OutJson::toJson($res['code'], $res['msg'], $res['data']);
    }

    public function test(Request $request)
    {
        $num = $request->input('num', '0');
        $res = $this->TaskServices->test($num);
        OutJson::toJson($res['code'], $res['msg'], $res['data']);
    }

}
